# coding:utf8
"""
test.py
"""
import requests
import os
import time
import json


def request_test():
	"""
	请求测试
	"""
	url = 'http://localhost:8001/test'
	post_data = {
		'param': '我是中午',	
	}
	r = requests.post(url, data=post_data)

	print r.status_code
	with open('a.txt', 'wb') as f:
		f.write(r.content)
	#print r.content


def add_file_path():
	"""
	获取文件路径
	"""
	fp = os.path.join(os.path.dirname(__file__), "asdf")
	print(fp)


def split_str(text):
	"""
	切割字符串
	"""
	mapped = dict()
	for line in text.split('\n'):
		for word in [x for x in line.split(' ') if len(x) > 0]:
			if word[0] not in mapped: mapped[word[0]] = []
			mapped[word[0]].append(word)
	print (mapped)


def get_unix_time():
	"""
	获取当前时间戳
	"""
	print (time.time())


def get_mongodb_conn():
	"""
	连接mongodb
	"""
	import pymongo as pm
	conn = pm.MongoClient('localhost', 27017)
	return conn


def get_mongo_database_names(conn):
	"""
	获取mongodb数据库名称
	"""
	return conn.database_names()


def get_db_collection_names(db_name):
	"""
	获取数据库内集合名称
	"""
	db = get_mongodb_conn()[db_name]
	return db.collection_names()


def get_collection(db_name, collection_name):
	"""
	获取集合中的文档
	"""
	db = get_mongodb_conn()[db_name]
	return db[collection_name]

# books = get_collection('bookstore', 'books')
request_test()

"""
test.py
"""